<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 16/3/24
 * Time: 上午10:28
 */
class AuthBaseController extends BaseController {

    public $layout = 'auth';
    public $breadCrumb  = '';


    public function beforeAction($action){
//         if(!AccAuth::isAdmin()){
//             exit('没有权限');
//         }

        if(parent::beforeAction($action)){
            $this->out['beforeAction']['Menu'] = $this->getMenu();

            return true;
        }else{
            return false;
        }
    }

    private static function getMenu(){
        $menu = array(
//             PubFunc::t('个人中心') => array(
//                 'icon'      => 'fa-users',
//                 'include'   => array(
//                     array('text' => PubFunc::t('个人信息'), 'url' => '/auth/?r=self/index'),
//                 ),
//             ),
            PubFunc::t('用户信息管理') => array(
                'icon'      => 'fa-users',
                'include'   => array(
                    array('text' => PubFunc::t('用户列表'), 'url' => '/auth/?r=user/index'),
                    array('text' => PubFunc::t('分组信息管理'), 'url' => '/auth/?r=role/index'),
                ),
            ),
            PubFunc::t('系统基础管理') => array(
                'icon'      => 'fa-users',
                'include'   => array(
                    array('text' => PubFunc::t('菜单信息管理'), 'url' => '/auth/?r=menu/index'),
                    array('text' => PubFunc::t('游戏管理'), 'url' => '/auth/?r=game/index'),
//                    array('text' => PubFunc::t('平台管理'), 'url' => '/auth/?r=platform/index')
                ),
            ),
        );

        if(!AccAuth::isAdmin()){
            $userRole = AccAuth::getUserRole();
            foreach($menu as $k=>&$v){
                foreach($v['include'] as $kk=>$vv){
                    $_arr = array_intersect($userRole, $vv['for']);

                    if(empty($_arr)){
                        unset($v['include'][$kk]);
                    }
                }

                if(empty($v['include'])){
                    unset($menu[$k]);
                }

            }
            unset($v);
        }

        return $menu;
    }
}